<template>
  <div class="addition">
    <MyHeader />
    <Form  ref="supForm" :model="supForm">
      <FormItem  class="addition_box" >
         <CheckboxGroup v-model="entnatureTmp">
        <Checkbox label="1">
            <span>总部企业</span>
        </Checkbox>
        <Checkbox label="2">
            <span>研发中心</span>
        </Checkbox>
        <Checkbox label="3">
            <span>总投资人为上年度世界500强企业</span>
        </Checkbox>
        <Checkbox label="4">
            <span>其他</span>
        </Checkbox>
    </CheckboxGroup>
      </FormItem>
      <FormItem class="addition_box" label="投资人是否有中央单位" :rules="validator.must"  prop="inviscenter">
        <i-Switch v-model="supForm.inviscenter" :true-value="'1'" :false-value="'2'">
          <span slot="open">是</span>
          <span slot="close">否</span>
        </i-Switch>
        <CheckboxGroup v-model="centertypeTmp" v-if="supForm.inviscenter == '1'">
          <Checkbox label="1" >
            <span>中央企业</span>
          </Checkbox>
          <Checkbox label="2">
            <span>中央在京事</span>
          </Checkbox>
          <br>
          <Checkbox label="3" >
            <span>驻京部队</span>
          </Checkbox>
          <Checkbox label="4" >
            <span>其他</span>
          </Checkbox>
        </CheckboxGroup>
      </FormItem>
      <FormItem class="addition_switch" label="法定代表人（负责人、执行合伙事务人、投资人）是否党员" :label-width="240"  :rules="validator.must" prop="leptispm">
        <i-Switch v-model="supForm.leptispm" :true-value="'1'" :false-value="'2'">
          <span slot="open">是</span>
        <span slot="close">否</span>
        </i-Switch>
      </FormItem>
      <div class="addition_space"></div>
      <FormItem class="addition_box" label="建立党组织" :rules="validator.must" prop="iscreatepo">
        <i-Switch v-model="supForm.iscreatepo" :true-value="'1'" :false-value="'2'">
          <span slot="open">是</span>
          <span slot="close">否</span>
        </i-Switch>
      </FormItem>
      <FormItem v-if="supForm.iscreatepo == '1'" class="addition_select" label="党组织建制" :label-width="120" :rules="validator.must" prop="parins">
        <Select v-model="supForm.parins"  placeholder="请选择党组织建制">
          <Option v-for="(item,index) in parinss" :value="item.value" :key="index">{{item.text}}</Option>
        </Select>
      </FormItem>
      <FormItem v-if="supForm.iscreatepo == '1'" class="addition_select" label="党组织组建方式" :label-width="130" :rules="validator.must" prop="parorgw">
        <Select v-model="supForm.parorgw"  placeholder="请选择党组织组建方式">
          <Option v-for="(item,index) in parorgws" :value="item.value" :key="index">{{item.text}}</Option>
        </Select>
      </FormItem>
      <FormItem class="addition_box" label="党组织是否本年度组建" :rules="validator.must" prop="iscreatepocuryear">
        <i-Switch v-model="supForm.iscreatepocuryear" :true-value="'1'" :false-value="'2'">
          <span slot="open">是</span>
          <span slot="close">否</span>
        </i-Switch>
      </FormItem>
      <FormItem class="addition_switch" label="法定代表人（负责人、执行合伙事务人、投资人、经营者）是否党书记" :label-width="240" :rules="validator.must" prop="leptispmo">
        <i-Switch v-model="supForm.leptispmo" :true-value="'1'" :false-value="'2'">
          <span slot="open">是</span>
          <span slot="close">否</span>
        </i-Switch>
      </FormItem>
      <div class="addition_space"></div>
      <FormItem class="addition_box" label="建立团组织" :rules="validator.must" prop="iscreateco">
        <i-Switch v-model="supForm.iscreateco" :true-value="'1'" :false-value="'2'">
          <span slot="open">是</span>
        <span slot="close">否</span>
        </i-Switch>
      </FormItem>
      <FormItem class="addition_input" label="团员人数" :label-width="120" prop='leaguenumber' :rules="validator.int"  v-if="supForm.iscreateco == '1'">
        <Input type="text" v-model="supForm.leaguenumber" placeholder="请输入团员人数" :maxlength="4"></Input>
      </FormItem>
      <FormItem class="addition_box" label="建立工会组织" prop='iscreatelu' :rules="validator.int">
        <i-Switch v-model="supForm.iscreatelu" :true-value="'1'" :false-value="'2'">
          <span slot="open">是</span>
        <span slot="close">否</span>
        </i-Switch>
      </FormItem>
      <FormItem class="addition_input" label="工会人数" :label-width="120" prop='unionnumber' :rules="validator.int"  v-if="supForm.iscreatelu == '1'">
        <Input type="text" v-model="supForm.unionnumber" placeholder="请输入工会人数" :maxlength="4" ></Input>
      </FormItem>
      <FormItem label="从业人数" :label-width="120" class="addition_input" prop='empnum' :rules="validator.int" >
        <Input type="text" v-model="supForm.empnum" placeholder="请输入从业人数" :maxlength="4"></Input>
      </FormItem>
      <FormItem label="本市人数" :label-width="120" class="addition_input" prop='empnumlocal' :rules="validator.int" >
        <Input type="text" v-model="supForm.empnumlocal" placeholder="请输入本市人数" :maxlength="4"></Input>
      </FormItem>
      <FormItem label="外地人数" :label-width="120" class="addition_input" prop='empnumnolocal' :rules="validator.int" >
        <Input type="text" v-model="supForm.empnumnolocal" placeholder="请输入外地人数" :maxlength="4"></Input>
      </FormItem>
      <FormItem label="女性人数" :label-width="120" class="addition_input" prop='femailnum' :rules="validator.int" >
        <Input type="text" v-model="supForm.femailnum" placeholder="请输入女性人数" :maxlength="4"></Input>
      </FormItem>
      <FormItem label="下岗人数" :label-width="120" class="addition_input" prop='laidoffnum' :rules="validator.int" >
        <Input type="text" v-model="supForm.laidoffnum " placeholder="请输入下岗人数" :maxlength="4"></Input>
      </FormItem>
      <div class="addition_space"></div>
      <FormItem class="addition_box addition_line" label="投资人中是否有本年度应届高校毕业生" :rules="validator.must" prop="hasnewgraivtr">
        <i-Switch v-model="supForm.hasnewgraivtr" :true-value="'1'" :false-value="'2'">
          <span slot="open">是</span>
          <span slot="close">否</span>
        </i-Switch>
      </FormItem>
      <FormItem  v-if="supForm.hasnewgraivtr == '1'" class="addition_box addition_line"  label="该毕业生是否为在京生源" :rules="validator.must" prop="hasnewgraivtrbj">
        <i-Switch  v-model="supForm.hasnewgraivtrbj" :true-value="'1'" :false-value="'2'">
          <span slot="open">是</span>
           <span slot="close">否</span>
        </i-Switch>
      </FormItem>
    </Form>
    <div class="addition_bottom">
      <div class="bottom">
    <Button type="warning" @click="saveInfo('supForm', false)">保存</Button>
    <Button type="primary" @click="gotoNext('supForm', true)">下一步</Button>
  </div>
      <MyFooter />
    </div>
  </div>
</template>

<script>
  import MyHeader from '../../components/MyHeader'
  import MyFooter from '../../components/MyFooter.vue'
  import request from '../../utils/request'
  import dictutil from '../../assets/js/dictutil'
  import validator from '../../utils/validatorUtil.js'
  export default {
    data() {
      return {
        validator,
        entnatureTmp: [],
        centertypeTmp: [],
        supForm: {},
        parinss: [],
        parorgws: []
      }
    },
    methods: {
      queryEntSup() {
        request.get('/interface/apply/cp/setup/queryEntSup.do', {gid: sessionStorage.getItem('gid')}
        ).then(response => {
          if (response.data.result === 'error') {
            this.$ErrorAlert(response.data.message)
          } else if (response.data.result === 'success') {
            this.supForm = response.data.data
            this.supForm.inviscenter = this.supForm.inviscenter === '1' ? '1' : '2'
            this.supForm.iscreatelu = this.supForm.iscreatelu === '1' ? '1' : '2'
            this.supForm.iscreatepo = this.supForm.iscreatepo === '1' ? '1' : '2'
            this.supForm.iscreatepocuryear = this.supForm.iscreatepocuryear === '1' ? '1' : '2'
            this.supForm.iscreateco = this.supForm.iscreateco === '1' ? '1' : '2'
            this.supForm.hasnewgraivtr = this.supForm.hasnewgraivtr === '1' ? '1' : '2'
            this.supForm.hasnewgraivtrbj = this.supForm.hasnewgraivtrbj === '1' ? '1' : '2'
            this.supForm.leptispmo = this.supForm.leptispmo === '1' ? '1' : '2'
            this.supForm.leptispm = this.supForm.leptispm === '1' ? '1' : '2'
            this.entnatureTmp = JSON.parse(this.supForm.entnature) || []
            this.centertypeTmp = JSON.parse(this.supForm.centertype) || []
          }
        })
      },
      getprolocother() {
        this.parinss = dictutil.getList('CZ05')
        this.parorgws = dictutil.getList('CZ06')
      },
      valiNum() {
        if (this.supForm.empnum * 1 !== this.supForm.empnumlocal * 1 + this.supForm.empnumnolocal * 1) {
          this.$ErrorAlert('从业人数与本市从业人数加外地从业人数的和不相等')
          return false
        }
        if (this.supForm.femaleNumber * 1 > this.supForm.empnum * 1) {
          this.$ErrorAlert('女性人数大于从业人数，数据有误')
          return false
        }
        if (this.supForm.laidoffNumber * 1 > this.supForm.empnum * 1) {
          this.$ErrorAlert('下岗人数大于从业人数，数据有误')
          return false
        }
        return true
      },
      save(name, isNext) {
        this.$refs[name].validate((valid) => {
          if (valid && this.valiNum()) {
            this.supForm.gid = sessionStorage.getItem('gid')
            this.supForm.entnature = JSON.stringify(this.entnatureTmp)
            this.supForm.centertype = this.supForm.inviscenter === '0' ? '' : JSON.stringify(this.centertypeTmp)
            if (this.supForm.iscreatepo === '2') {
              this.supForm.parins = ''
              this.supForm.parorgw = ''
            }
            if (this.supForm.iscreateco === '2') {
              this.supForm.leaguenumber = ''
            }
            if (this.supForm.iscreatelu === '2') {
              this.supForm.unionnumber = ''
            }
            if (this.supForm.hasNewGraIvtr === '2') {
              this.supForm.hasNewGraIvtrBj = ''
            }
            let postData = new FormData()
            postData.append('supForm', JSON.stringify(this.supForm))
            request.post('/interface/apply/cp/setup/updateEntSup.do', postData
              ).then(response => {
                if (response.data.result === 'error') {
                  this.$ErrorAlert(response.data.message)
                } else if (response.data.result === 'success') {
                    if (isNext) {
                      this.$router.push('/record')
                     } else {
                    this.$SuccessAlert('保存成功')
                     }
                }
              })
          } else {
            this.$ErrorAlert('数据未填写完全，请注意红色标记')
          }
       })
      },
      saveInfo(name, isNext) {
        this.save(name, isNext)
      },
      gotoNext(name, isNext) {
        this.save(name, isNext)
      }
    },
    mounted() {
      this.queryEntSup()
      this.getprolocother()
    },
    components: {
      MyHeader,
      MyFooter
    }
  }

</script>

<style lang="scss">
  .addition {
    position: relative;
    min-height: 100%;
    background: #f3f3f3;
    padding-bottom: 3rem;
    form {
      background: #fff;
    }
    .ivu-form-item {
      margin-bottom: 0;
      padding: 0 0.54rem;
      border-bottom: 1px solid #dedede;
      label {
        font-size: 0.57rem;
      }
      &-label {
        text-align: left;
        line-height: 1.5;
      }
      &-content {
        font-size: 0.57rem;
        line-height: 1.5rem;
        .ivu-checkbox-group {
          .ivu-checkbox-wrapper {
            line-height: 1;
          }
        }
      }
    }
    &_input {
      input {
        height: 1.5rem;
        font-size: 0.57rem;
        border-top: none;
        border-bottom: none;
        border-right: none;
        border-radius: 0;
        text-align: center;
        &:hover {
          border: none;
        }
        &:focus {
          border: none;
          box-shadow: none;
        }
        &::-webkit-input-placeholder {
          text-align: right;
        }
        &::-moz-placeholder {
          text-align: right;
        }
        &:-ms-input-placeholder {
          text-align: right;
        }
      }
    }
    &_radio {
      height: 1.75rem;
      line-height: 1.75rem;
      display: flex;
      justify-content: space-between;
      .ivu-radio {
        margin-right: 1.1rem;
        &-inner {
          display: none;
        }
        &-input {
          top: -0.55rem;
          border: none;
          outline: none;
          opacity: 1;
          -webkit-appearance: none;
          -moz-appearance: none;
          appearance: none;
          background: transparent;
          &:before {
            color: #aaa;
            content: "\F401";
            font-family: Ionicons;
            font-size: 1rem;
            -webkit-font-smoothing: antialiased;
          }
          &:checked:before {
            color: #00b3ff;
            content: "\F3FF";
          }
        }
      }
    }
    &_check {
      height: 1.75rem;
      line-height: 1.75rem;
      .ivu-form-item-content {
        line-height: inherit;
        padding-left: 1.1rem;
        input {
          transform: translateX(-130%);
          height: 100%;
        }
      }
    }
    &_select{
      .ivu-form-item-content{
        .ivu-select-placeholder{
          line-height: 1.75rem;
        }
        .ivu-select-selected-value{
          line-height: 1.75rem;
        }
      .ivu-select{
        height: 1.75rem;
        line-height: 1.75rem;
        .ivu-select-selection{
           height: 1.75rem;
           line-height: 1.75rem;
           border: none;
           outline: none;
           .ivu-select-placeholder{
             font-size: .54rem;
             height: 1.75rem;
             line-height: 1.75rem
           }
        }
      }
      }
    }
    &_box {
      .ivu-form-item-content {
        clear: left;
        .ivu-switch {
          float: right;
          margin-top: -1.25rem;
        }
        .ivu-select {
          margin-bottom: 0.36rem;
          &-selection {
            height: 1.5rem;
          }
          &-placeholder {
            height: 1.5rem;
            line-height: 1.5rem;
            font-size: 0.5rem;
          }
        }
      }
      &-input {
        input {
          height: 1.5rem;
          line-height: 1.5rem;
          margin-bottom: 0.32rem;
          &::-webkit-input-placeholder {
            font-size: 0.5rem;
          }
          &::-moz-placeholder {
            font-size: 0.5rem;
          }
          &:-ms-input-placeholder {
            font-size: 0.5rem;
          }
        }
      }
    }
    &_switch {
      .ivu-switch {
        float: right;
        margin-top: 1rem;
      }
    }
    &_space {
      height: 0.54rem;
      background: #f3f3f3;
    }
    &_line {
      border-bottom: 0 !important;
    }
    &_bottom {
      position: absolute;
      width: 100%;
      bottom: 0;
    }
  }
.bottom {
    display: flex;
    justify-content: space-around;
    // padding: 0.54rem;
    button {
      width: 45%;
      padding-top: 0.18rem;
      padding-bottom: 0.36rem;
      font-size: 0.57rem;
    }
  }
</style>
